package com.timeDeal.servlet;







import com.timeDeal.bean.GuanliyuanBean;
import com.timeDeal.service.AdminService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


/**
 * Created by Administrator on 2016/7/24.
 */

public class AdminLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String zhanghao = request.getParameter("zhanghao");
        String mima = request.getParameter("mima");
        AdminService adminService =new  AdminService();
        try {
            boolean result = adminService.dologin(zhanghao,mima);
            System.out.println(zhanghao);
            System.out.println(result);
            System.out.println("22222222222222222222222222");
            if (result) {
                GuanliyuanBean aguanliyuan= new GuanliyuanBean();
                aguanliyuan.setZhanghao(zhanghao);
                request.getSession().setAttribute("ADMIN", aguanliyuan);
                PrintWriter out = response.getWriter();
                out.print("<script>alert(\"login sucessful!\");</script>") ;
                request.getRequestDispatcher("/admin/guanli.jsp").forward(request,response);
            } else {
                PrintWriter out = response.getWriter();
                out.print("<script contentType=“text/html;charset=UTF-8”>alert(\"error!\");</script>") ;
                request.getRequestDispatcher("/admin/login.jsp").forward(request,response);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
